﻿using mds.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mds.Configuration
{
   public class ConfigurationManager
    {
       private Dictionary<string, Object> configlist;
       private static ConfigurationManager _instance = new ConfigurationManager();
       public static ConfigurationManager Instance
       {
           get
           {
               return _instance;
           }
       }
       private ConfigurationManager()
       {
           configlist = new Dictionary<string, Object>();          
       }
       public T GetService<T>(string appPlusId)
       {
           if (configlist.ContainsKey(appPlusId))
               return (T)configlist[appPlusId];
           else
           {
               if (!configlist.ContainsKey(appPlusId))
                 {
                     var classObject = ConfigurationReader.Instance.ReadForSingle<T>(appPlusId);
                     if (classObject != null)
                     {
                         configlist.Add(appPlusId,classObject);
                     }
                     return classObject;
                 }
                 else {
                     return (T)configlist[appPlusId];
                 }
           }
       }
    }
}
